package com.connector.server.redis;

import redis.clients.jedis.JedisPubSub;

public abstract class AbstractRedisPubSubListener extends JedisPubSub
{
    private String currentPattern;
    private String currentChannel;
    private boolean pattern;
    
    public String getCurrentPattern() {
        return this.currentPattern;
    }
    
    private void setCurrentPattern(final String currentPattern) {
        this.currentPattern = currentPattern;
    }
    
    public String getCurrentChannel() {
        return this.currentChannel;
    }
    
    private void setCurrentChannel(final String currentChannel) {
        this.currentChannel = currentChannel;
    }
    
    public boolean isPattern() {
        return this.pattern;
    }
    
    private void setPattern(final boolean pattern) {
        this.pattern = pattern;
    }
    
    public void unsubscribe() {
        super.unsubscribe();
    }
    
    public void unsubscribe(final String... channels) {
        super.unsubscribe(channels);
    }
    
    public void subscribe(final String... channels) {
        super.subscribe(channels);
    }
    
    public void onMessage(final String channel, final String message) {
        super.onMessage(channel, message);
        this.setCurrentChannel(channel);
        this.setPattern(false);
        this.doMessage(message);
    }
    
    public void onSubscribe(final String channel, final int subscribedChannels) {
        super.onSubscribe(channel, subscribedChannels);
    }
    
    public void onUnsubscribe(final String channel, final int subscribedChannels) {
        super.onUnsubscribe(channel, subscribedChannels);
    }
    
    public void psubscribe(final String... patterns) {
        super.psubscribe(patterns);
    }
    
    public void punsubscribe() {
        super.punsubscribe();
    }
    
    public void punsubscribe(final String... patterns) {
        super.punsubscribe(patterns);
    }
    
    public void onPMessage(final String pattern, final String channel, final String message) {
        super.onPMessage(pattern, channel, message);
        this.setCurrentChannel(channel);
        this.setCurrentPattern(pattern);
        this.setPattern(true);
        this.doMessage(message);
    }
    
    public void onPSubscribe(final String pattern, final int subscribedChannels) {
        super.onPSubscribe(pattern, subscribedChannels);
    }
    
    public void onPUnsubscribe(final String pattern, final int subscribedChannels) {
        super.onPUnsubscribe(pattern, subscribedChannels);
    }
    
    public abstract void doMessage(final String message);
}
